/*  //法一：
    function intersection(arr1, arr2) {
    let set = new Set(arr1);
    let result = [];

    for (let i = 0; i < arr2.length; i++) {
        if (set.has(arr2[i])) {
            result.push(arr2[i])
        }
    }

    return result;
} */

// 法二：
function intersection(arr1, arr2) {
    return arr1.filter(function (value, index) {
        return arr2.indexOf(value) >= 0;
    })
}

let arr1 = [1, 2, 3, 4, 5];
let arr2 = [4, 1, 5, 8, 9, 6, 7];

console.log(intersection(arr1, arr2));